
#include "PipelineManager.h"

using namespace ttg_internal::utils;

//-----------------------
//--- PipelineManager ---
//-----------------------

ttg::math::uint64 PipelineManager::createPipeline(ttg_internal::pipeline::LitePipelineInfo &pipeline)
{
	Lock();
	Pipeline ^res = gcnew Pipeline(pipeline);
	ttg::math::uint64 ID = curID++;
	_pipelines->Add(res);
	_pipelineIDs->Add(ID, res);
	UnLock();
	return ID;
}

Pipeline ^PipelineManager::findPipeline(ttg::math::uint64 ID)
{
	Lock();
	Pipeline ^res;
	bool v = _pipelineIDs->TryGetValue(ID, res);
	UnLock();
	if (v)
		return res;
	else
		return nullptr;
}

void PipelineManager::releasePipeline(ttg::math::uint64 ID)
{
	Lock();
	Pipeline ^res = findPipeline(ID);
	if (res != nullptr)
	{
		_pipelines->Remove(res);
		_pipelineIDs->Remove(ID);
	}
	UnLock();
}
